<div id="pie_to_be"></div>
<style>
div#pie_to_be {
width: 50px;
height: 50px;
position: fixed;
top:50px;
right:10px;
margin: 15px;
color:#444444;
font-family:arial;
font-size:32px;
}
</style>
<?php
$time = "";
$id_subject = $this->uri->segment(3,0);
$q = $this->db->query("select time from subject where id_subject='$id_subject' limit 1");
foreach ($q->result() as $re):
		$time = $re->time;
endforeach;
$time = $time*$time;

?>
<script>

var myseconds = <?php echo $time?>;
var mycolor = 'rgba(255, 10, 0, 0.8)';

//alert('You will have '+Math.floor(myseconds/60)+' minutes and '+myseconds%60+' seconds to finish. Press "OK" to begin.');

$(function(){
$('div#pie_to_be').pietimer({
seconds: myseconds,
color: mycolor
},
function(){ $('#quiz').submit(); });});

(function($){jQuery.fn.pietimer=function(options,callback){var settings={'seconds':10,'color':'rgba(255, 255, 255, 0.8)','height':this.height(),'width':this.width()};if(options){$.extend(settings,options);}this.html('<canvas id="pie_timer" width="'+settings.height+'" height="'+settings.height+'">'+settings.seconds+'</canvas>');var val=360;interval=setInterval(timer,40);function timer(){var canvas=document.getElementById('pie_timer');if(canvas.getContext){val-=(360/settings.seconds)/24;if(val<=0){clearInterval(interval);canvas.width=canvas.width;if(typeof callback=='function'){callback.call();}}else{canvas.width=canvas.width;var ctx=canvas.getContext('2d');var canvas_size=[canvas.width,canvas.height];var radius=Math.min(canvas_size[0],canvas_size[1])/2;var center=[canvas_size[0]/2,canvas_size[1]/2];ctx.beginPath();ctx.moveTo(center[0],center[1]);var start=(3*Math.PI)/2;ctx.arc(center[0],center[1],radius,start-val*(Math.PI/180),start,false);ctx.closePath();ctx.fillStyle=settings.color;ctx.fill();}}}return this;};})(jQuery);
var isMSIE = /*@cc_on!@*/0;
if(isMSIE){function ticker(){document.getElementById('pie_to_be').innerHTML=parseInt(document.getElementById('pie_to_be').innerHTML)-1;}
setInterval("ticker()",1000);setTimeout("document.getElementById('quiz').submit()",myseconds*1000);}
</script>

<script>
 var _gaq = [['_setAccount', 'UA-6960372-1'], ['_trackPageview']];
 (function(d, t) {
  var g = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
  g.async = true;
  //g.src = ('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  s.parentNode.insertBefore(g, s);
 })(document, 'script');
</script>


<form id="quiz" name="quiz" method="post" action="<?php echo base_url()?>sas/answer/<?php echo $this->uri->segment(3,0)?>">

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
  <td align="left"><span class="padding-left-30 margin-left-30">
    <input type="submit" name="button" id="button" value="Submit" class="uiButtonRounded" /></span></td>
</tr>
<?php
$shuffled_query = $query->result_array();
shuffle ($shuffled_query);
$num = 0;
foreach($shuffled_query as $row):
	
	$num++;
?>
  <tr>
    <td>
    <table width="100%" border="0" cellspacing="1" cellpadding="2">
      <tr>
        <td width="30" valign="top"><?php echo $num?></td>
        <td><?php echo $row['que']?></td>
      </tr>
      <tr>
        <td valign="top" class="padding-left-20"><input type="radio" name="<?php echo $row['id_radio']?>" id="<?php echo $row['id_radio']?>" value="<?php echo $row['a']?>" /></td>
        <td><?php echo $row['a']?></td>
      </tr>
      <tr>
        <td valign="top" class="padding-left-20"><input type="radio" name="<?php echo $row['id_radio']?>" id="<?php echo $row['id_radio']?>" value="<?php echo $row['b']?>" /></td>
        <td><?php echo $row['b']?></td>
      </tr>
      <tr>
        <td valign="top" class="padding-left-20"><input type="radio" name="<?php echo $row['id_radio']?>" id="<?php echo $row['id_radio']?>" value="<?php echo $row['c']?>" /></td>
        <td><?php echo $row['c']?></td>
      </tr>
      <tr>
        <td valign="top" class="padding-left-20"><input type="radio" name="<?php echo $row['id_radio']?>" id="<?php echo $row['id_radio']?>" value="<?php echo $row['d']?>" /></td>
        <td><?php echo $row['d']?></td>
      </tr>
      <tr>
        <td valign="top" class="padding-left-20"><input type="radio" name="<?php echo $row['id_radio']?>" id="<?php echo $row['id_radio']?>" value="<?php echo $row['e']?>" /></td>
        <td><?php echo $row['e']?></td>
      </tr>
    </table><br />
    </td>
  </tr>
<?php endforeach;?>
<tr>
  <td align="left"><span class="padding-left-30 margin-left-30">
    <input type="submit" name="button" id="button" value="Submit" class="uiButtonRounded" /></span></td>
</tr>
</table>

</form>